package com.lc.controller;

import com.lc.feign.ClientAFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author:LiChuang
 * Date: 2022/8/9 10:13
 */

@RestController
public class TestController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private ClientAFeign clientAFeign;
    /*
    做服务发现，两个服务必须在同一个命名空间下且在同一个分组中；否则不能发现服务；
     */
    @GetMapping("/testService")
    public String testService(){
        List<ServiceInstance> instances = discoveryClient.getInstances("nacos-client-b");
        System.out.println("instances：" + instances.get(0).getUri().toString());
        return clientAFeign.BInfo();
    }

}
